package per.dg.digital_klotski.utils;

import android.content.Context;
import android.content.SharedPreferences;

public class SharedPreferencesManager {

    public static final String SHAREDPREFERENCES_NAME = "jing_chess";
    public static final String SHAREDPREFERENCES_KEY_PLAY1_NAME = "player_1_name";
    public static final String SHAREDPREFERENCES_KEY_PLAY2_NAME = "player_2_name";
    public static final String SHAREDPREFERENCES_KEY_CHESSMAN = "chessman";
    public static final String SHAREDPREFERENCES_KEY_ALL_CHESS = "all_chess";
    public static final String SHAREDPREFERENCES_KEY_SOUND = "sound";
    public static final String SHAREDPREFERENCES_KEY_MUSIC = "music";

    public static final String INTENT_KEY_MODE = "intent_mode";
    public static final String INTENT_KEY_CHESSMAN = "intent_chessman";
    
    public static SharedPreferencesManager INSTANCE;

    public static SharedPreferencesManager getInstance(Context mContext){
        if(INSTANCE == null){
            synchronized (SharedPreferencesManager.class){
                if(INSTANCE == null){
                    INSTANCE = new SharedPreferencesManager(mContext);
                }
            }
        }
        return INSTANCE;
    }

    SharedPreferences mSharedPreferences;
    SharedPreferences.Editor mEdit;

    private SharedPreferencesManager(Context mContext){
        mSharedPreferences = mContext.getSharedPreferences(SHAREDPREFERENCES_NAME, Context.MODE_PRIVATE);
        mEdit = mSharedPreferences.edit();
    }

    public void saveSound(boolean sound){
        mEdit.putBoolean(SHAREDPREFERENCES_KEY_SOUND, sound);
        mEdit.commit();
    }

    public boolean getSound(){
        return mSharedPreferences.getBoolean(SHAREDPREFERENCES_KEY_SOUND, true);
    }

    public void saveMusic(boolean music){
        mEdit.putBoolean(SHAREDPREFERENCES_KEY_MUSIC, music);
        mEdit.commit();
    }

    public boolean getMusic(){
        return mSharedPreferences.getBoolean(SHAREDPREFERENCES_KEY_MUSIC, true);
    }

}
